package org.gaming;

import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import com.tool.btn.MoBanBtn;
import com.tool.role.RoleData;
import org.come.Frame.ZhuFrame;
import org.come.entity.GamingQuestions;
import org.come.socket.Agreement;
import org.come.socket.SendMessageUntil;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.math.BigDecimal;

/**
 * 召唤兽面板按钮
 *
 * @author Administrator
 */
public class GaminglBtn extends MoBanBtn {
    private GamingJpanel gamingJpanel;
    /**
     * 1是改名 2是参战 3休息 4加点 5驯养 6技能 7物品 8炼妖 9 放生 10抗性 11 召唤 12 观看 13隐藏
     */
    private Integer typeBtn;


    public GaminglBtn(String iconpath, int type, Color[] colors, Font font, String text, Integer typeBtn, GamingJpanel gamingJpanel) {
        // TODO Auto-generated constructor stub
        super(iconpath, type, colors);
        this.setText(text);
        setFont(font);
        this.typeBtn = typeBtn;
        setVerticalTextPosition(SwingConstants.CENTER);
        setHorizontalTextPosition(SwingConstants.CENTER);
        this.gamingJpanel = gamingJpanel;
    }

    @Override
    public void chooseyes() {
        // TODO Auto-generated method stub

    }

    @Override
    public void chooseno() {
        // TODO Auto-generated method stub

    }

    @Override
    public void nochoose(MouseEvent e) {
        if (typeBtn <= 4) {
            gamingJpanel.clearBorder();
            this.setBorder(BorderFactory.createLineBorder(Color.red));
            gamingJpanel.setIndex(typeBtn);
        } else {

            if(gamingJpanel.getYz().isVisible() == false){
                ZhuFrame.getZhuJpanel().addPrompt("请勿重复押注#35");
                return;
            }
            //验证金额
            String text = gamingJpanel.getBetAmount().getText();
            long l = Long.parseLong(text);
            if (l <= 0) {
                ZhuFrame.getZhuJpanel().addPrompt("我们这不接受赊账#35");
                return;
            }
            if (l > 1000000000l) {
                ZhuFrame.getZhuJpanel().addPrompt("超过投注限制1000000000#35");
                return;
            }
            if (gamingJpanel.getIndex() <= 0 || gamingJpanel.getIndex() >= 5) {
                ZhuFrame.getZhuJpanel().addPrompt("客官,请选择正确的押注类型");
                return;
            }

            BigDecimal gold = RoleData.getRoleData().getLoginResult().getGold();
            if (gold.longValue() < l) {
                ZhuFrame.getZhuJpanel().addPrompt("小兄弟你的赌本不够#17");
                return;
            }
            // 扣金币
//            RoleData.getRoleData().getLoginResult().setGold(RoleData.getRoleData().getLoginResult().getGold().subtract(new BigDecimal(l)));

            GamingQuestions gamingQuestions = new GamingQuestions();
            gamingQuestions.setCode(1);
            gamingQuestions.setGamingType(gamingJpanel.getIndex());
            gamingQuestions.setMoney(l);
            String sendmes = "62|" + JSONUtil.toJsonStr(gamingQuestions);

            SendMessageUntil.toServer(Agreement.getAgreement().gangbattle(sendmes));
        }

    }


}
